x = input()
max =0
if len(x) != 4:    
    pass
else:
    v = list(x)
    
    for t in range(0, 3):        
        for i in range(2,int(v[t]+v[t+1])): 
            if int(v[t]+v[t+1]) % i == 0:                
                break 
        else:            
            if int(v[t]+v[t+1])>max:
                max = int(v[t]+v[t+1])    
    for k in v:
        for i in range(2, int(k)):            
            if int(k) % i == 0:
                break        
        else:
            if int(k)>max: 
                max=int(k)    
    for i in range(2, int(x)):
        if int(x)%i == 0:            
            break
    else:        
        if max< int(x):
            max = int(x)    
    for z in range(1,3):
        for i in range(2,int(v[z-1]+v[z]+v[z+1])):             
            if int(v[z-1]+v[z]+v[z+1]) % i == 0:
                break        
        else:
            if int(v[z-1]+v[z]+v[z+1])>max:                 
                max = int(v[z-1]+v[z]+v[z+1])
print(max)